package com.cheer.controller;

import com.cheer.bo.*;
import com.cheer.common.Result;
import com.cheer.dto.MatchResultDTO;
import com.cheer.service.AuthService;
import com.cheer.service.MatchService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;
import javax.validation.Valid;
import java.util.List;

/**
 * @author cheer
 */
@RestController
@RequestMapping("/match")
@Slf4j
public class MatchController {

    @Autowired
    private AuthService authService;

    @Autowired
    private MatchService matchService;

    @GetMapping("/home")
    public Result<MatchHomeBO> getMatchHome(HttpSession session) {
        MatchHomeBO matchHomeBO = matchService.getMatchHome(authService.getUserId(session));
        return Result.success(matchHomeBO);
    }

    @GetMapping("/start")
    public Result<MatchBO> startMatch(@RequestParam Integer type, HttpSession session) {
        return Result.success(matchService.startMatch(authService.getUserId(session), type));
    }

    @GetMapping("/practice")
    public Result<List<QuestionBO>> getQuestions(@RequestParam Integer start) {
        return Result.success(matchService.getQuestions());
    }

    @PostMapping("/end")
    public Result<MatchResultBO> endMatch(@RequestBody @Valid MatchResultDTO matchResultDTO, HttpSession session) {
        return Result.success(matchService.endMatch(matchResultDTO, authService.getUserId(session)));
    }

    @GetMapping("/record")
    public Result<MatchRecordBO> getRecord(HttpSession session) {
        return Result.success(matchService.getRecord(authService.getUserId(session)));
    }

    @GetMapping("/export")
    public void exportMatchHistory() {
        matchService.exportMatchHistory();
    }

    /**
     * 大学习颂词点赞数据导出
     */
    /*@GetMapping("/exportVideoHistory")
    public void exportVideoHistory() {
        matchService.exportVideoHistory();
    }*/

}
